<template>
	<view class="" style="background-color: #fff;">
		<topMenu :show-back="true" title="订单详情" :menu="[]"></topMenu>
		<u-list  @scrolltolower="scrolltolower">
			<u-swipe-action  size="large"  >
				<u-list-item height="180rpx"  v-for="item in order" :key="item.id" :index="item.id">
				
					<u-swipe-action-item :autoClose="true" :options="action">
						<u-cell @touchstart="showDetail(item)" @click="showDetail(item)" :title="item.date" :value="item.settlementText" arrow="false">
							<view slot="value" :class="{
							'text-yellow':item.isSettlement == 2,
							'text-green':item.isSettlement == 1
							}">
								{{item.settlementText}}
							</view>
								<u-icon slot="right-icon" :name="item.show ? 'arrow-up' : 'arrow-down'"></u-icon>
						</u-cell>
					</u-swipe-action-item>
				</u-list-item>
			</u-swipe-action>
		</u-list>
	</view>
</template>

<script>
	
	const app = getApp()
	import {
		getOrderList,
		delOrder
	} from '@/api/index.js'
	import {setText} from '@/utils/utils.js'
	export default {
		name: 'OrderList',
		data() {
			return {
				loading: false,
				clientHeight: app.globalData.clientHeight - 50 - 30,
				finished: false,
				refresh: false,
				showAction: false,
				total: 0,
				pageNum: 1,
				orderId: 0,
				pageSize: 30,
				order: [],
				companyId: null,
				merchantId: null,
				actionRow: null,
				action: [{
					text: '删除',
					style: {
						backgroundColor: "red"
					}
				}]
			}
		},
		computed: {
			pageCount() {
				return Math.ceil(this.total / this.pageSize) > 0 ? Math.ceil(this.total / this.pageSize) : 1
			},
			orderInfo() {
				let orderInfo = []
				
				console.log(orderInfo)
				return orderInfo
			}
		},
		created() {
			this.getOrder()
		},
		onLoad(options) {
			this.companyId = options.companyId
			this.merchantId = options.merchantId
		},
		methods: {
			async getOrder() {
				if (this.refresh) {
					this.order = []
					this.pageNum = 1
					this.refresh = false
				}
				if (this.pageCount < this.pageNum) {
					this.finished = true
					return false;
				}
				this.loading = true
				const res = await getOrderList({
					companyId: this.companyId,
					merchantId: this.merchantId,
					pageNum: this.pageNum,
					pageSize: this.pageSize
				})
				res.rows.forEach(item => {
					item.settlementText = setText[item.isSettlement]
					item.show = false
				})
				this.total = res.total
				this.order = [...this.order, ...res.rows]
				this.pageNum++
				this.loading = false
			},
			showDetail(row) {
				uni.navigateTo({
					url:`/pages/index/pages/addOrderDetail?orderId=${row.id}&type=edit`
				})
			},
			async beforeClose(row) {
				const flag = await this.$modal.confirm(`是否删除此订单`)
				if (!flag) return false
				const res = await delOrder(row.id)
				if (res.code == 200) {
					this.$modal.msgSuccess("删除成功")
					this.refresh = true
					this.getOrder()
				}
			},
			handleImage(url) {
				uni.previewImage({
					urls: [url]
				})
			},
			scrolltolower(){
				this.getOrder()
			}

		}

	}
</script>

<style scoped>
	.van-button--danger {
		height: 100%;
	}
	.u-swipe-action{
		height: 100rpx;
		
		.u-swipe-action-item{
			height: 100rpx;
		}
		.u-cell__body{
			height: 98rpx;
		}
	}
</style>